﻿var isBack = true;
function goBack() {
    if (isBack) {
        location.href = "/Province/ProvinceList";
    }
    else {
        location.href = '/Province/ProvinceAdd';
    }
}
function chengeBack(op)
{
    isBack = op;
}
function SubData() {
    var postData = {
        ProvinceName: $("#ProvinceName").val().trim(),
        IsActive: $("#PIsActive").val(),
        Remark: HtmlUtil.htmlEncodeByRegExp(CKEDITOR.instances.desTextarea.getData())
    };
    //使用异步进行修改数据的信息
    $.post("/Province/AddInfo", postData, function (date) {
        if (date == "repeat") {
            $.alert({
                title: '系统提示',
                content: '重复数据无法添加！',
                confirm: function () {
                }
            });
        }

        else if (date == "err" || date == "") {
            $.alert({
                title: '系统提示',
                content: '操作失败！',
                confirm: function () {
                }
            });
        }
        else {
            goBack();
        }
    });
}
$(function () {
    $("#rightResources").addClass("active");
    CKEDITOR.replace('desTextarea', {
        toolbar: 'Basic'
        //uiColor: '#9AB8F3'//界面颜色
    });

    $('#ProvAddForm')
    .bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            ProvinceName: {
                message: 'The username is not valid',
                validators: {
                    notEmpty: {
                        message: 'The Province Name is required and can\'t be empty'
                    }
                }
            }
        }
    })
    .on('success.form.bv', function (e) {
        e.preventDefault();
        SubData();
    });
});